//
//  TZL_SystemApiConfig.h
//  MyTabbarDemo
//
//  Created by Yuki on 2021/10/11.
//  这里主要是获取手机信息、当前app的版本信息的api

#ifndef TZL_SystemApiConfig_h
#define TZL_SystemApiConfig_h

#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>

/// 获取屏幕宽度
NS_INLINE CGFloat TZL_ScreenWidth(){
    return  UIScreen.mainScreen.bounds.size.width;
}

/// 获取屏幕高度
NS_INLINE CGFloat TZL_ScreenHeight(){
    return UIScreen.mainScreen.bounds.size.height;
}

/// 获取电池栏的高度
NS_INLINE CGFloat TZL_StateBarHeight(){
    CGFloat stateBarHeight = 0.0;
    if (@available(iOS 13.0, *)) {
        UIStatusBarManager *statebarMange = UIApplication.sharedApplication.windows.firstObject.windowScene.statusBarManager;
        stateBarHeight = statebarMange.statusBarFrame.size.height;
    }
    stateBarHeight = UIApplication.sharedApplication.statusBarFrame.size.height;
    
    return stateBarHeight;
}

/// 导航栏高度
NS_INLINE CGFloat TZL_NavgationHeight(){
    return 44.0 + TZL_StateBarHeight();
}

/**
 16进制颜色
 @param hex 16进制值
 @param alpha 透明度
 @return UIcolor类型 颜色
 */
NS_INLINE UIColor *ColorHex(NSInteger hex , CGFloat alpha){
    return [UIColor colorWithRed:(((hex & 0xFF0000) >> 16))/255.0 green:(((hex & 0xFF00) >>8))/255.0 blue:((hex & 0xFF))/255.0 alpha:alpha];
}

/**
 16进制颜色
 @param hexStr 16进制值
 @return UIcolor类型 颜色
 */
NS_INLINE UIColor *ColorHexStr(NSString *hexStr){
    NSString * cString = [[hexStr stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
       // String should be 6 or 8 characters
       if ([cString length] < 6) return [UIColor blackColor];
       // strip 0X if it appears
       if ([cString hasPrefix:@"0X"]) cString = [cString substringFromIndex:2];
       if ([cString hasPrefix:@"#"]) cString = [cString substringFromIndex:1];
       if ([cString length] != 6) return [UIColor blackColor];
       // Separate into r, g, b substrings
       NSRange range;
       range.location = 0;
       range.length = 2;
       NSString * rString = [cString substringWithRange:range];
       range.location = 2;
       NSString * gString = [cString substringWithRange:range];
       range.location = 4;
       NSString * bString = [cString substringWithRange:range];
       // Scan values
       unsigned int r, g, b;
       [[NSScanner scannerWithString:rString] scanHexInt:&r];
       [[NSScanner scannerWithString:gString] scanHexInt:&g];
       [[NSScanner scannerWithString:bString] scanHexInt:&b];
       return [UIColor colorWithRed:((float)r / 255.0f)
                              green:((float)g / 255.0f)
                               blue:((float)b / 255.0f)
                              alpha:1];
}





#endif /* TZL_SystemApiConfig_h */
